//login.js
//获取应用实例
var app = getApp();
var httpclient = require('../../utils/httpclient.js')
Page({
  data: {
    remind: '加载中',
    angle: 0,
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userInfo: {},
    encryptedData: '',
    iv: '',
    openId: '',
    unionId: '',
    nickname: '',
    loginCode: ''
  },
  goToIndex:function(){
    wx.switchTab({
      url: '/pages/group/group',
    });
  },
  onLoad:function(){
    // 查看是否授权
    // wx.getSetting({
    //   success(res) {
    //     if (res.authSetting['scope.userInfo']) {
    //       // 已经授权，可以直接调用 getUserInfo 获取头像昵称
    //       wx.getUserInfo({
    //         success: function (res) {
    //           app.globalData.userInfo = res.userInfo
    //         }
    //       })
    //     }
    //   }
    // })
  },
  onShow:function(){

  },
  onReady: function(){
    var that = this;
    setTimeout(function(){
      that.setData({
        remind: ''
      });
    }, 1000);
    wx.onAccelerometerChange(function(res) {
      var angle = -(res.x*30).toFixed(1);
      if(angle>14){ angle=14; }
      else if(angle<-14){ angle=-14; }
      if(that.data.angle !== angle){
        that.setData({
          angle: angle
        });
      }
    });
  },
  getUserInfo: function (e) {
    app.getUserInfo(e.detail);
    var that = this;
    app.globalData.userInfo = e.detail.userInfo;
    //测试使用
    that.goToIndex();
    //请求登录
    
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true,
      loginCode: app.globalData.loginCode
    })

 

  }
});